﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using System.Data.Common;

namespace Chenxin.Lib.Business.DAL
{
    /// <summary>
    /// 数据访问类v_PrintBillInfo。
    /// </summary>
    public class v_PrintBillInfo
    {
        public v_PrintBillInfo()
        { }
        #region  成员方法
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public static Chenxin.Lib.Business.Entity.v_PrintBillInfo GetModel(Guid BillId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * from v_PrintBillInfo ");
            strSql.Append(" where BillId=@BillId");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "BillId", DbType.Guid, BillId);
            Chenxin.Lib.Business.Entity.v_PrintBillInfo model = null;
            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                if (dataReader.Read())
                {
                    model = ReaderBind(dataReader);
                }

                dataReader.Close();
                dataReader.Dispose();
            }
            return model;
        }

        /// <summary>
        /// 对象实体绑定数据
        /// </summary>
        public static Chenxin.Lib.Business.Entity.v_PrintBillInfo ReaderBind(IDataReader dataReader)
        {
            Chenxin.Lib.Business.Entity.v_PrintBillInfo model = new Chenxin.Lib.Business.Entity.v_PrintBillInfo();
            object ojb;
            ojb = dataReader["ContractId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ContractId = new Guid(ojb.ToString());
            }
            else
            {
                model.ContractId = Guid.Empty;
            }

            model.ContractCode = dataReader["ContractCode"].ToString();
            model.BillEmployeeL = dataReader["BillEmployeeL"].ToString();
            model.BillDepartNameL = dataReader["BillDepartNameL"].ToString();

            ojb = dataReader["BillId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.BillId = new Guid(ojb.ToString());
            }
            model.BillCode = dataReader["BillCode"].ToString();
            ojb = dataReader["InOrOut"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.InOrOut = (int)ojb;
            }
            model.FundName = dataReader["FundName"].ToString();
            model.CustomerName = dataReader["CustomerName"].ToString();
            ojb = dataReader["BillDepartId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.BillDepartId = new Guid(ojb.ToString());
            }
            model.BillDepartName = dataReader["BillDepartName"].ToString();
            model.BillOprEmpName = dataReader["BillOprEmpName"].ToString();

            ojb = dataReader["BargainPrice"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.BargainPrice = (decimal)ojb;
            }

            ojb = dataReader["BillMoney"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.BillMoney = (decimal)ojb;
            }
            ojb = dataReader["BillDate"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.BillDate = string.Format("{0:yyyy-MM-dd}", ojb);
            }
            model.BillMemo = dataReader["BillMemo"].ToString();
            ojb = dataReader["BusinessType"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.BusinessType = (int)ojb;
            }
            model.HouseAddress = dataReader["HouseAddress"].ToString();
            ojb = dataReader["VenderDepartId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.VenderDepartId = new Guid(ojb.ToString());
            }
            model.VenderDepartName = dataReader["VenderDepartName"].ToString();
            ojb = dataReader["VenderUserId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.VenderUserId = new Guid(ojb.ToString());
            }
            model.VenderUserName = dataReader["VenderUserName"].ToString();
            ojb = dataReader["BuyerDepartId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.BuyerDepartId = new Guid(ojb.ToString());
            }
            model.BuyerDepartName = dataReader["BuyerDepartName"].ToString();
            ojb = dataReader["BuyerUserId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.BuyerUserId = new Guid(ojb.ToString());
            }
            model.BuyerUserName = dataReader["BuyerUserName"].ToString();
            model.CustomerType = dataReader["CustomerType"].ToString();

            model.PayBankType = dataReader["PayBankType"].ToString();
            model.PayBankName = dataReader["PayBankName"].ToString();
            model.PayBankNo = dataReader["PayBankNo"].ToString();

            ojb = dataReader["CanGetSaleMoney"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CanGetSaleMoney = (decimal)ojb;
            }

            ojb = dataReader["GetedSaleMoney"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.GetedSaleMoney = (decimal)ojb;
            }

            ojb = dataReader["PayedSaleMoney"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.PayedSaleMoney = (decimal)ojb;
            }
            return model;
        }
        #endregion  成员方法
    }
}

